#ifndef _KBLOCK_H
#define KBLOCK_H
#include <linux/net.h>
#include <linux/in.h>
#include <linux/fs.h>
#include <linux/blkdev.h>
#include <linux/sched.h>
#include <linux/completion.h>

#define KBLOCK_CAPACITY 16*1024*1024
#define KBLOCK_DEVNAME "kblock"
#define KBLOCK_PORT 7879
#define KBLOCK_ADDR "192.168.46.128"
#define KBLOCK_MAGIC 0x46716236
#define BACK_DISK "/dev/sdb1"

enum kblock_role {
    KBLOCK_MASTER,
    KBLOCK_SLAVE
};

enum kblock_status {
    KBLOCK_DISCONNECTED,
    KBLOCK_CONNECTED,
    KBLOCK_EXIT
};

enum kblock_data_type {
    KBLOCK_HANDSHAKE,
    KBLOCK_BIO
};

struct data_head {
    unsigned int magic;
    int type;
    unsigned int data_len;
    sector_t sector;
};

struct kblock_device {
    int major;
    struct gendisk *vdisk;
    struct block_device *physics_device;
    struct request_queue *queue;
    struct socket *data_sock;
    struct socket *listen_sock;
    struct task_struct *thread_work;
    struct completion work_completion;
    int flag;
    atomic_t status;
};

void kblock_bio_endio(struct bio *bio,int error);
#endif